'''
Created on 21-04-2011

@author: pawel
'''
import os, shutil

def ensure_dir(f):
    d = os.path.dirname(f)
    if not os.path.exists(d):
        os.makedirs(d)

f = open('../cats.txt', 'r');

catFileMap = dict()

for line in f:
    lineArr = line.split(" ")
    if len(lineArr) == 2:
        filename = lineArr[0]
        cat = lineArr[1].replace("\n", "")
        if not catFileMap.has_key(cat):
            catFileMap[cat] = list()
        catFileMap.get(cat).append(filename)
        
for (cat, fileList) in catFileMap.items():
    for file in fileList:
        fileArr = file.split("/")
        fileDir = "../result/" + fileArr[0] + "/" + cat + "/" + fileArr[1]
        ensure_dir(fileDir)
        shutil.copy2("../" + file, fileDir)
     



